/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.sml.SEFM.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import vn.com.sml.SEFM.BUS.fraudStandardBUS;
import vn.com.sml.SEFM.domain.Fraudstandard;

/**
 *
 * @author Tunp
 */
public class UpdateFraudStandardController implements Controller {
    fraudStandardBUS fraudstandardBUS = new fraudStandardBUS();

    public void setFsBUS(fraudStandardBUS fsBUS) {
        this.fraudstandardBUS = fsBUS;
    }
    
    @Override
    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
        String domesticLimit = hsr.getParameter("domesticLimit");
        String foreignLimit = hsr.getParameter("foreignLimit");
        
        String updateFraud = hsr.getParameter("updateFraud");
        
        String updateid = hsr.getParameter("updateId");
        
         if(updateFraud==null) {
            ModelAndView mv = new ModelAndView("UpdateFraudStandard");
            int id = Integer.parseInt(updateid);
            Fraudstandard fs = fraudstandardBUS.getFraudStandardById(id);
            mv.addObject("fs",fs);
            return mv;
        }
        else {
            int id = Integer.parseInt(updateid);
            Fraudstandard fs = fraudstandardBUS.getFraudStandardById(id);
            fs.setDomesticLimit(Integer.parseInt(domesticLimit));
            fs.setForeignLimit(Integer.parseInt(foreignLimit));
            
            fraudstandardBUS.update(fs);
            
            ModelAndView mv = new ModelAndView("redirectFraudStandard");
            return mv;
        }
    }
    
}
